package com.leave.service.Impl;

import java.util.HashMap;
import java.util.List;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.leave.dao.LeaveMapper;
import com.leave.entity.Leave;
import com.leave.entity.User;
import com.leave.service.ILeaveService;

@Service
public class LeaveServiceImpl implements ILeaveService {
	@Autowired
	private LeaveMapper leaveMapper;
	
	public int addLeave(Leave leave) {
		int i = leaveMapper.insertSelective(leave);
		
		return i;
	}

	public HashMap<String,Object> getLeaveByPage(Integer page, Integer rows,int userId) {
		PageHelper.startPage(page,rows);
		List<Leave> leaveList = leaveMapper.getLeaveByPage(userId);
		PageInfo<Leave> pageInfo = new PageInfo<Leave>(leaveList);
		Long total = pageInfo.getTotal();
		HashMap<String,Object> map = new HashMap<String,Object>();
		map.put("leaveList", leaveList);
		map.put("total", total);
		
		return map;
	}

	public Leave getLeaveByLeaveId(int id) {
		return leaveMapper.selectByPrimaryKey(id);
	}

	public int updateLeaveByLeave(Leave leave) {
		return leaveMapper.updateByPrimaryKeySelective(leave);
	}

	public Leave getLeaveByProcessInstanceId(String processInstanceId) {
		Leave leave = leaveMapper.getLeaveByProcessInstanceId(processInstanceId);
		
		
		
		return leave;
	}


}
